package gamegame;

public class MapLocation {
	/**
	 * A basic as shit interface for entering commands.
	 */
	public static interface Command {
		int action(String anything);
	}
	String description; //Location description.
	String[][] validCommands; //List of commands.
	Command[] results; //List of results.
	String[][] defCommands; //Default commands (pronounced deef-command)
	Command[] defResults; //Default results (pronounced def-results)
	int i,j;
	public MapLocation(String desc, int commands)
	{
		j = 0;
		String[] def;
		defCommands = new String[4][];
		defResults = new Command[4];
		def = new String[3];
		def[0] = "h";
		def[1] = "help";
		def[2] = "ayudame";
		addDefCommand(def, new MapLocation.Command(){
			public int action(String anything){
				System.out.println("Just type shit to do actions. If you want to go somewhere, type the cardinal direction.\n" +
						"Other useful commands may include: take OBJECT, examine OBJECT, wait, eat OBJECT, use OBJECT");
				return 0;
			}
		});
		def = new String[2];
		def[0] = "kill self";
		def[1] = "commit suicide";
		addDefCommand(def, new MapLocation.Command(){
			public int action(String anything){
				System.out.println("We know that was probably a joke, but if you are actually experiencing problems in your life\n"+
						"and need to talk to someone about it we recommend you call a suicide hotline at 1-800-273-8255");
				return 0;
			}
		});
		def = new String[1];
		def[0] = "wait";
		addDefCommand(def, new MapLocation.Command(){
			public int action(String anything){
				int q = (int)(Math.random()*10);
				if(q == 0)
					System.out.println("You wait around for a bit.");
				else if(q == 1)
					System.out.println("Um...spaceship. Yeah. OK, quit wasting time.");
				else if(q == 2)
					System.out.println("I wasn't prepared for this level of procrastination.");
				else if(q == 3)
					System.out.println("Well shit. Now what?");
				else if(q == 4)
					System.out.println("You waste some time. While playing a text adventure. How meta.");
				else if(q == 5)
					System.out.println("You idle about because you're tired. Shoulda had some Recaf.");
				else if(q == 6)
					System.out.println("There are only 10 wait messages. I hope you're counting.");
				else if(q == 7)
					System.out.println("You gape cluelessly. Much like an English major in a Computer Science class.");
				else if(q == 8)
					System.out.println("You wait around for so long that you die of dehydration. Just kidding!");
				else if(q == 9)
					System.out.println("Curly moustache! YOU SO PRINGLES!");
				return 1;
			}
		});
		def = new String[4];
		def[0] = "quit";
		def[1] = "exit";
		def[2] = "save";
		def[3] = "close";
		addDefCommand(def, new MapLocation.Command(){
			public int action(String anything){
				System.exit(0);
				return 0;
			}
		});
		description = desc;
		if(commands < 0)
		{
			validCommands = null;
			results = null;
			i = -1;
		}
		else
		{
			validCommands = new String[commands][];
			results = new Command[commands];
			i = 0;
		}
	}
	/**
	 * Used for producing new commands for a map location. See GameGame notes for how to use.
	 */
	public void addCommand(String[] v, Command c)
	{
		if(i >= results.length)
			System.out.println("No more commands possible.");
		else
		{
			validCommands[i] = v;
			results[i] = c;
			i++;
		}
	}
	public void addDefCommand(String[] v, Command c)
	{
		if(j >= defResults.length)
			System.out.println("No more commands possible.");
		else
		{
			defCommands[j] = v;
			defResults[j] = c;
			j++;
		}
	}
	/**
	 * Actually looks through each possible command and see if what the user typed matches up.
	 */
	public int execute(String cmd)
	{
		for(int i = 0; i < validCommands.length; i++)
		{
			for(int j = 0; j < validCommands[i].length; j++)
			{
				if(cmd.equalsIgnoreCase(validCommands[i][j]))
					return results[i].action(cmd);
			}
		}
		for(int i = 0; i < defCommands.length; i++)
		{
			for(int j = 0; j < defCommands[i].length; j++)
			{
				if(cmd.equalsIgnoreCase(defCommands[i][j]))
					return defResults[i].action(cmd);
			}
		}
		System.out.println("We, the Derpsigners, do not recognize this as a valid command. Rethink your actions.");
		return 0;
	}
	/**
	 * Self explanatory, but I'm making comments so I don't forget all this shit when I wake up tomorrow.
	 */
	public String toString()
	{
		return description;
	}
}
